#!/usr/bin/env python

from httputil import HttpUtil
from config import logger

class Volume(HttpUtil):
  def __init__(self, prefixURL=None):
    HttpUtil.__init__(self, prefixURL)

  def createVolume(self, name, zoneid, diskOfferingId):
    command = "createVolume"
    logger.debug("command=" + command)
    args = {
             "name": name,
             "zoneid": zoneid,
             "diskofferingid": diskOfferingId
           }
    response = self.http_get(command, args=args, async=True)
    logger.debug(response)
    return response["volume"]

  def listVolumes(self):
    command = "listVolumes"
    logger.debug("command=" + command)
    response = self.http_get(command)
    logger.debug(response)
    return response

  def attachVolume(self, volumeid, virtualmachineid):
    command = "attachVolume"
    logger.debug("command=" + command)
    args = {
             "id": volumeid,
             "virtualmachineid": virtualmachineid
           }
    response = self.http_get(command, args=args, async=True)
    logger.debug(response)
    return response["volume"]

  def detachVolume(self, volumeid):
    command = "detachVolume"
    logger.debug("command=" + command)
    args = {"id": volumeid}
    response = self.http_get(command, args=args, async=True)
    logger.debug(response)
    return response["volume"]


  def deleteVolume(self, volumeid):
    command = "deleteVolume"
    logger.debug("command=" + command)
    args = {"id": volumeid}
    response = self.http_get(command, args=args)
    logger.debug(response)
    return response


